package com.ruoyi.mall.product.interfaces.facade;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mall.product.domain.service.IPmsCategoryBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.mall.product.domain.entity.PmsCategoryBrand;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 品牌分类关联Controller
 *
 * @author zhangqishu
 * @date 2022-05-25
 */
@RestController
@RequestMapping("/category/brand")
public class PmsCategoryBrandController extends BaseController
{
    @Autowired
    private IPmsCategoryBrandService pmsCategoryBrandService;

    /**
     * 查询品牌分类关联列表
     */
    @RequiresPermissions("product:brand:list")
    @GetMapping("/list")
    public TableDataInfo list(PmsCategoryBrand pmsCategoryBrand)
    {
        startPage();
        List<PmsCategoryBrand> list = pmsCategoryBrandService.selectPmsCategoryBrandList(pmsCategoryBrand);
        return getDataTable(list);
    }

    /**
     * 导出品牌分类关联列表
     */
    @RequiresPermissions("product:brand:export")
    @Log(title = "品牌分类关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsCategoryBrand pmsCategoryBrand)
    {
        List<PmsCategoryBrand> list = pmsCategoryBrandService.selectPmsCategoryBrandList(pmsCategoryBrand);
        ExcelUtil<PmsCategoryBrand> util = new ExcelUtil<PmsCategoryBrand>(PmsCategoryBrand.class);
        util.exportExcel(response, list, "品牌分类关联数据");
    }

    /**
     * 获取品牌分类关联详细信息
     */
    @RequiresPermissions("product:brand:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pmsCategoryBrandService.selectPmsCategoryBrandById(id));
    }

    /**
     * 新增品牌分类关联
     */
    @RequiresPermissions("product:brand:add")
    @Log(title = "品牌分类关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsCategoryBrand pmsCategoryBrand)
    {
        return toAjax(pmsCategoryBrandService.insertPmsCategoryBrand(pmsCategoryBrand));
    }

    /**
     * 修改品牌分类关联
     */
    @RequiresPermissions("product:brand:edit")
    @Log(title = "品牌分类关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsCategoryBrand pmsCategoryBrand)
    {
        return toAjax(pmsCategoryBrandService.updatePmsCategoryBrand(pmsCategoryBrand));
    }

    /**
     * 删除品牌分类关联
     */
    @RequiresPermissions("product:brand:remove")
    @Log(title = "品牌分类关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsCategoryBrandService.deletePmsCategoryBrandByIds(ids));
    }
}
